<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>toJSON() 方法</title>
</head>
<body>
  <script>
    const book = {
      title: 'Professional JavaScript',
      authors: [
        'Nicholas C. Zakas',
        'Matt Frisbie'
      ],
      edition: 4,
      year: 2017,
      toJSON() {
        return this.title;
      }
    };
    const jsonText = JSON.stringify(book);

    console.log(jsonText);  // "Professional JavaScript"
  </script>
</body>
</html>